#include <iostream>
#include <vector>
#include <string>

class HasPtr
{
public:
    static std::string cpp;
    HasPtr(const std::string& ps);

    HasPtr(const HasPtr& ptr);

    HasPtr& operator=(const HasPtr& ptr);

    void print();

    ~HasPtr();

private:
    std::string* p;
    int i;
};

std::string HasPtr::cpp = "c++11";

HasPtr::HasPtr(const std::string& ps) : p(new std::string(ps)), i(0) {}

HasPtr::HasPtr(const HasPtr& ptr) : p(new std::string(*ptr.p)), i(ptr.i)
{}

HasPtr& HasPtr::operator=(const HasPtr& ptr)
{
    if(this == &ptr)
    {
        return *this;
    }

    auto newp = new std::string(*ptr.p);
    if(p != NULL)
        delete p;
    p = newp;
    i = ptr.i;
    return *this;
}

void HasPtr::print()
{
    std::cout << *p << std::endl;
}

HasPtr::~HasPtr()
{
    if(p != NULL)
        delete p;
}

int main()
{
    std::cout << HasPtr::cpp << std::endl;

    std::string* p = new std::string("hellow world");
    std::cout << *p << std::endl;
    std::string* pp = new std::string(*p);
    std::cout << *pp << std::endl;


    HasPtr test_ptr("hello");
    test_ptr.print();

    HasPtr test_ptr2 = test_ptr;
    test_ptr2.print();

    HasPtr test_ptr3("world");
    test_ptr3 = test_ptr2;
    test_ptr3.print();

    return 0;
}